#include "iot_gpio.h"
#include "iot_gpio_ex.h"
#include "iot_pwm.h"

#define LED_GPIO_IDX 6

#define LED_USE_PWM 0
#define LED_PWM_CHN 3

int g_light_state = 0;

int light_init(){

    IoTGpioInit(LED_GPIO_IDX);
    IoTGpioSetFunc(LED_GPIO_IDX, IOT_GPIO_FUNC_GPIO_6_GPIO);
    IoTGpioSetDir(LED_GPIO_IDX,IOT_GPIO_DIR_OUT);


}
int light_onoff(int onoff){
   
    IoTGpioSetOutputVal(LED_GPIO_IDX,onoff ? 1 : 0);

    g_light_state = onoff ? 1 : 0;

}

int get_light_state(){

    return g_light_state;
}

int light_brightness(int percent)
{
    if(percent >= 100){
        percent = 99;
    }
    if(percent <= 0){
        percent == 0;
        IoTPwmStop(LED_PWM_CHN);
        return 0;
    }
    IoTPwmStart(LED_PWM_CHN, percent, 10000);

    return 0;
}


